﻿namespace PowerSong.UserInterface
    {
    using System;
    using PowerSong.SongDatabase;
    using System.Windows.Media;

    public class Settings
        {

        private Database database = null;
        
        public Settings(Database database)
            {
            this.database = database;
            }

        public string ActiveBibleTranslation
            {
            get
                {
                return database.Settings.Get("ActiveBibleTranslation");
                }
            set
                {
                database.Settings.Set("ActiveBibleTranslation", value);
                }
            }

        public Style DefaultStyle
            {
            get
                {
                var identifier = database.Settings.GetGuid("DefaultStyle");
                return identifier == Guid.Empty ? null : database.Styles.Get(identifier);
                }
            set
                {
                database.Settings.Set("DefaultStyle", value == null ? Guid.Empty : value.ID);
                }
            }

        public License DefaultLicense
            {
            get
                {
                var identifier = database.Settings.GetGuid("DefaultLicense");
                return identifier == Guid.Empty ? null : database.Licenses.Get(identifier);
                }
            set
                {
                database.Settings.Set("DefaultLicense", value == null ? Guid.Empty : value.ID);
                }
            }
        
        public bool PopupSongPreviews
            {
            get
                {
                return database.Settings.Get<bool>("PopupSongPreviews");
                }
            set
                {
                database.Settings.Set("PopupSongPreviews", value);
                } 
            }

        public bool EnableReporting
            {
            get
                {
                return database.Settings.Get<bool>("EnableReporting");
                }
            set
                {
                database.Settings.Set("EnableReporting", value);
                }
            }

        public bool AutoCreateProjectionWindow
            {
            get
                {
                return database.Settings.Get<bool>("AutoCreateProjectionWindow");
                }
            set
                {
                database.Settings.Set("AutoCreateProjectionWindow", value);
                }
            }

        public uint NoticeBackgroundColour
            {
            get
                {
                return database.Settings.Get<uint>("NoticeBackgroundColour", Colors.DarkBlue.ToUInt());
                }
            set
                {
                database.Settings.Set("NoticeBackgroundColour", value);
                }
            }

        public uint NoticeTextColour
            {
            get
                {
                return database.Settings.Get<uint>("NoticeTextColour", Colors.White.ToUInt());
                }
            set
                {
                database.Settings.Set("NoticeTextColour", value);
                }
            }

        public int NoticeTimeToAppear
            {
            get
                {
                return database.Settings.Get<int>("NoticeTimeToAppear", 1000);
                }
            set
                {
                database.Settings.Set("NoticeTimeToAppear", value);
                }
            }

        public int NoticeTimeToDissappear
            {
            get
                {
                return database.Settings.Get<int>("NoticeTimeToDissappear", 1000);
                }
            set
                {
                database.Settings.Set("NoticeTimeToDissappear", value);
                }
            }

        public double NoticeSpeed
            {
            get
                {
                return database.Settings.Get<double>("NoticeSpeed", 0.15);
                }
            set
                {
                database.Settings.Set("NoticeSpeed", value);
                }
            }

        public int NoticeDuration
            {
            get
                {
                return database.Settings.Get<int>("NoticeDuration", 5000);
                }
            set
                {
                database.Settings.Set("NoticeDuration", value);
                }
            }

        public string NoticeFontName
            {
            get
                {
                return database.Settings.Get<string>("NoticeFontName", "Verdana");
                }
            set
                {
                database.Settings.Set("NoticeFontName", value);
                }
            }

        public double NoticeFontSize
            {
            get
                {
                return database.Settings.Get<double>("NoticeFontSize", 0.15);
                }
            set
                {
                database.Settings.Set("NoticeFontSize", value);
                }
            }

        public FontEffectType NoticeFontStyle
            {
            get
                {
                return (FontEffectType)Enum.Parse(typeof(FontEffectType),
                                                  database.Settings.Get<string>("NoticeFontStyle",
                                                                                FontEffectType.None.ToString()));
                }
            set
                {
                database.Settings.Set("NoticeFontStyle", value.ToString());
                }
            }

        public void SaveChanges()
            {
            database.Settings.SaveChanges();
            }

        }

    }
